// components/dynamic/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,
      value: {
        img: "/assets/img/message/mountain.png",
        title: "城旅社区精选推荐：周末城市徒步路线",
        type: "攻略",
        comments: 128,
        stars: 532
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onDynamicTap: function(e) {
      const item = this.properties.item
      
      wx.showModal({
        title: item.title,
        content: `作者：${item.author || '城旅社区'}\n发布时间：${item.publishTime || '刚刚'}\n类型：${item.type}\n点赞：${item.stars} 评论：${item.comments}`,
        showCancel: true,
        cancelText: '关闭',
        confirmText: '查看详情',
        success: function(res) {
          if (res.confirm) {
            wx.showToast({
              title: '详情页面开发中',
              icon: 'none'
            })
          }
        }
      })
    },
    
    onLikeTap: function(e) {
      e.stopPropagation()
      const item = this.properties.item
      const newStars = item.stars + 1
      
      this.triggerEvent('like', {
        id: item.id,
        stars: newStars
      })
      
      wx.showToast({
        title: '点赞成功',
        icon: 'success'
      })
    },
    
    onCommentTap: function(e) {
      e.stopPropagation()
      wx.showToast({
        title: '评论功能开发中',
        icon: 'none'
      })
    }
  }
})
